<?php

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$gametype = intval(getvar("gametype"));
$id = intval(getvar("id"));
require_once( "class_3d/CheckMode_3d.php" );

if (!isset($_SESSION['CHK_master_account_OK']) || $_SESSION['CHK_master_account_OK'] != 1)
{
    header("Location: op.php?op=admin&fp=amountchkpass&gametype={$gametype}&id={$id}&t=-1");
    exit();
}

require( "class_3d/Bet_3d.php" );
$chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
$chk->checkShow3dPage();
$g_betname_3or5 = judge_type($gametype, true);
$chkGametype = chkGametype($gametype);
unset($chk);
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();

$Bet_3d = new Bet_3d($gametype);
$result = $Bet_3d->getMyBetLimitRS($id);
$row = mysql_fetch_array($result);
if (!$row)
{
    $ui->showErrorPage("<p class=error>注单不存在或为已经过账注单！</p>");
    exit();
}
if (getvar("act") == "save")
{
    if ($gametype == 0)
    {
        getdb("Update bet Set numbers='" . getvar("numbers") . "',line_nums='" . getvar("line_nums") . "' Where id={$row['id']}");
        getdb("Update xbet Set numbers='" . getvar("numbers") . "',line_nums='" . getvar("line_nums") . "' Where id={$row['id']}");
        echo "<script type='text/javascript'>alert('修改完成,需重新颁奖！');location.href='?op.php?op=admin&fp=b2&gametype={$gametype}&id={$row['id']}';</script>";
    }
    else
    {
        $fields = array();
        $fields['user_id'] = $row['user_id'];
        $fields['lotto_id'] = $row['lotto_id'];
        $fields['bettype'] = $row['bettype'];
        $fields['subid'] = $row['subid'];
        $fields['numbers'] = "'" . getvar("numbers") . "'";
        $fields['amount'] = $row['amount'];
        $fields['rate'] = $row['rate'];
        $fields['rate5'] = $row['rate5'];
        $fields['payoff'] = $row['payoff'];
        $fields['disk'] = $row['disk'];
        $fields['line_nums'] = "'" . getvar("line_nums") . "'";
        $fields['unitmoney'] = $row['unitmoney'];
        $fields['State'] = $row['State'];
        $fields['ip'] = "'" . $row['ip'] . "'";
        $fields['back1'] = $row['back1'];
        $fields['back2'] = $row['back2'];
        $fields['back3'] = $row['back3'];
        $fields['back4'] = $row['back4'];
        $fields['back5'] = $row['back5'];
        $fields['back6'] = $row['back6'];
        $fields['percent2'] = $row['percent2'];
        $fields['percent3'] = $row['percent3'];
        $fields['percent4'] = $row['percent4'];
        $fields['percent5'] = $row['percent5'];
        $fields['percent255'] = $row['percent255'];
        $fields['acl2'] = $row['acl2'];
        $fields['acl3'] = $row['acl3'];
        $fields['acl4'] = $row['acl4'];
        $fields['acl5'] = $row['acl5'];
        $fields['r2'] = $row['r2'];
        $fields['r3'] = $row['r3'];
        $fields['r4'] = $row['r4'];
        $fields['r6'] = $row['r6'];
        $fields['createtime'] = $row['createtime'];
        $sessid = enBetSessid($fields);
        getdb("Update {$Bet_3d->table_name} Set numbers='" . getvar("numbers") . "',line_nums='" . getvar("line_nums") . "',sessid='{$sessid}' Where id={$row['id']}");
        getdb("Update x{$Bet_3d->table_name} Set numbers='" . getvar("numbers") . "',line_nums='" . getvar("line_nums") . "',sessid='{$sessid}' Where id={$row['id']}");
        $chkGametype = chkGametype($gametype);
        if ($chkGametype < 1)
        {
            exit();
        }
        if ($chkGametype == 3)
        {
            include_once( "class_5h/class.lotto5h.php" );
            $lotto3d = new lotto5h($gametype);
        }
        else
        {
            include_once( "class_3d/class.lotto3d.php" );
            $lotto3d = new lotto3d($gametype);
        }
        $fields = array();
        $fields['state'] = "1";
        switch ($chkGametype)
        {
            case 1 :
                $stopTime = date("Hi");
                break;
            case 2 :
            case 3 :
                $fields['calcbet'] = "1";
                break;
            default :
                exit();
                break;
        }
        db_update("lotto_{$tbl}", $fields, "id={$row['lotto_id']}");
        $postTime = $conf->get("paper_post_bet");
        $today = date("Hi") <= $postTime ? date("Y-m-d", strtotime("-1 day")) : date("Y-m-d");
        $lotto_id = $lotto3d->CheckLottoOpen($row['lotto_id']);
        if ($row['rame'] != 0)
        {
            if ($lotto_id == $row['lotto_id'])
            {
                $conf->set("calcbet_{$tbl}", "1");
                $x = $lotto3d->openDate == $today ? "" : "x";
                $lotto3d->OpenProcess($lotto_id, $x);
                if ($gametype == 12)
                {
                    $sql = "SELECT open FROM lotto_3s3 WHERE id = {$lotto_id} LIMIT 1";
                    $rs = getdb($sql);
                    if (!$rs->eof)
                    {
                        $sql = "SELECT id FROM lotto_3s3 WHERE open = '{$rs->f[0]}' ORDER BY openbet DESC LIMIT 1";
                        $rs = getdb($sql);
                        if (!$rs->eof && $rs->f[0] == $lotto_id)
                        {
                            include_once( "class_3d/Amounts_float_3d.php" );
                            $AmountFloat3D = new Amounts_float_3d();
                            $AmountFloat3D->countBet($lotto_id, "3s3", $x);
                        }
                    }
                }
                if (in_array($chkGametype, array(2, 3)))
                {
                    db_update("lotto_{$tbl}", array("calcbet" => "0"), "id={$row['lotto_id']}");
                }
                $conf->set("calcbet_{$tbl}", "0");
            }
        }
        echo "<script type='text/javascript'>alert('修改完成！');location.href='?op.php?op=admin&fp=b2&gametype={$gametype}&id={$row['id']}';</script>";
    }
    exit();
}
$ui->header();
echo "<style> .span3da{ color:#0200A0;} </style>";
echo "<form method=\"post\" action=\"?op.php?op=admin&fp=b2&gametype={$gametype}&id={$row['id']}\">";
echo "<input type=\"hidden\" name=\"act\" value=\"save\"/>";
echo "<table width=900 border=1 cellpadding=3 cellspacing=0>";
echo "<thead>";
echo "<tr class=\"bgImg_{$gametype}\"><th colspan=\"10\" style=\"font-size:13px;text-align:left;padding-left:10px;border-left:0;\"><span style='float:left'>{$tblName} 下注清单</th></tr>";
echo "<tr class=\"bgClc_{$gametype}\"  align=center><td nowrap>单号 / 时间</td><td nowrap>会员 / 退水</td><td nowrap>盘类 / 期数 / 开奖日期</td><td nowrap>下注内容</td><td nowrap>下注金额</td><td nowrap>赔率</td><td nowrap>退水</td><td nowrap>结果</td><td nowrap>备注</td><td nowrap>IP</td>";
echo "</thead>";
echo "<tbody>";
echo "<tr class=\"td2\">";
echo "<td nowrap><font color=\"green\">" . $row['id'] . "</font>&nbsp;&nbsp;" . date("m-d H:i:s", $row['createtime']) . "</td>";
echo "<td nowrap><span {$showUrlFlag} onclick=\"javascript:paper(" . $row['user_id'] . ");\">" . $row['account'] . "</span>&nbsp;&nbsp;<font color=\"green\">" . round(100 - $row['back1'], 2) . "</font></td>";
echo "<td nowrap>" . $g_disk_name[$row['disk']] . "&nbsp;/&nbsp;" . $row['round'] . "期&nbsp;<font color=\"green\">" . $row['open'] . "</font></td>";
echo "<td nowrap>";
if ($_5hFlag)
{
    echo "<font class='colorXY'>" . $RateConfig_3d->xyidTitle[$row['xyid']] . "</font>";
}
if ($gametype == 0)
{
    echo "【" . GetBetContent($row['bettype'], $row['numbers'], $row['amount']) . "】&nbsp;<input name=\"numbers\" type=\"text\" size=\"4\" value=\"" . $row['numbers'] . "\" /><input name=\"line_nums\" type=\"text\" size=\"5\" value=\"" . $row['line_nums'] . "\" /></td>";
}
else
{
    echo "【" . $g_betname_3or5[$row['bettype'] . "_" . $row['subid']] . "】&nbsp;<input name=\"numbers\" type=\"text\" size=\"4\" value=\"" . $row['numbers'] . "\" /><input name=\"line_nums\" type=\"text\" size=\"5\" value=\"" . nl2br($row['line_nums']) . "\" /></td>";
}
if (20000 < $row['amount'])
{
    $color = "alert2";
}
else if (10000 < $row['amount'])
{
    $color = "alert1";
}
else
{
    $color = "";
}
echo "<td nowrap align=\"right\" class=\"" . $color . "\">" . $row['amount'] . "</td>";
echo "<td nowrap align=\"right\">" . floatval($row['rate']) . "</td>";
echo "<td nowrap align=\"right\">" . round($row['a1'], 2) . "</td>";
echo "<td nowrap align=\"right\">" . say_numbercolor($row['b1'], 3) . "</td>";
if ($row['rame'] == 1)
{
    $note = "<font color=red>- 逾时 -</font>";
}
else if ($row['rame'] == 2)
{
    $note = "<font color=red>- 取消 -</font>";
}
else if ($row['rame'] == 3)
{
    $note = "<font color=red>- 异常 -</font>";
}
if (chkBet_peace($row))
{
    $note .= " <font class='betpeace'>和局</font>";
}
if ($curruser['acl'] == 255)
{
    $note .= floatval($row['rate5']) ? "<font class=\"c5\" color=\"red\">[" . floatval($row['rate5']) . "]</font>" : "";
}
echo "<td nowrap>" . $row['rame'] . '   ' . $note . "</td>";
echo "<td nowrap>{$row['ip']}</td>";
echo "</tr>";
echo "<tr class = \"td2\">";
echo "<td height=\"50\" colspan=\"10\" align=\"center\"><input type=\"submit\" name=\"button\" id=\"button\" value=\" 更改 \" /></td>";
echo "</tr>";
echo "</tbody>";
echo "</table>";
echo "</form>";
$ui->footer();
?>